﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace StateManager
{
    class Truck : moveObject
    {
        // the constructor for the truck class.

        public Truck(Direction facing, Level lvl, float time, float x, float y, float velx, int pace)
            : base(facing, time, x, y, velx, pace)
        {
            random = new Random();


            if (facing == Direction.Left)
                pos = new Vector2(x, y);
            else
                pos = new Vector2(x - 120, y);
            // this method loads the textures needed for this object by using the content manager
            // within the level object

        }

        // this method loads all of the needed images that will be used in the game into memory
        // the level object is required in order to use the content manager inside it
        public void loadContent(Level lvl, int randomnum)
        {
            //tex = lvl.Content.Load<Texture2D>("images/truck");
            tex = Truck.randomCarThing(randomnum, lvl.Content);

            sFont = lvl.Content.Load<SpriteFont>("font/SpriteFont1");
        }

        public void setSpeed() // sets the pacing between each of the items
        {
            timeWait = tex.Width / Vel.X * 45 * pace;
        }


        // this method draws the object on screen as well as any other information
        public override void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            

            if (dir == Direction.Left)
                spriteBatch.Draw(tex, colRec, null, Color.White, 0, Vector2.Zero, SpriteEffects.FlipHorizontally, 0);
            else
                spriteBatch.Draw(tex, pos, Color.White);  // the image for the truck is drawn on screen
        }

        public static Texture2D randomCarThing(int num, ContentManager content)
        {
            if (num < 4 && num > 0)
                return content.Load<Texture2D>("images/cars/car" + num.ToString());
            else
                throw new NotImplementedException("Number given into car giving thing is out of range");
            //break;
        }
    }
}
